<?php
/**
 * Estro Slider con efecto ken burns
 * http://www.odjevents.com/intro/docs/kenburns_help_file.html
 * http://www.squaresites.net/blog/estro-slider-ken-burns-effect.html
 * @author danidhsm
 *
 */
class kenburns extends CI_Controls{

	/**
	 *
	 * Enter Array con solo el nombre de la imagen que se le pasará al control
	 * @var array
	 */
	public $images;


	public $thumbs;

	/**
	 *
	 * tiempo en segundos en el que aparecera la siguiente imagen
	 * @var int
	 */
	public $delay;
	/**
	 *
	 * duracion del efecto ken burn en segundos,por defecto 15
	 * @var int
	 */
	public $duration;
	/**
	 *
	 * Tipo de zoom,tipos in,out o random
	 * @var string
	 */
	public $zoom;

	//data-autopause="image" data-thumb="enabled" data-mode="kb" data-controls="always" data-shadow="enabled"
	public $autopause="image";

	public $thumb="enabled";

	public $mode="kb";

	public $controls;

	public $shadow="enabled";
	function __construct(){
		parent::__construct();
		$this->images=array();
	}

	function drawContent(){
		$div= new div();
		$div->atributos=$this->atributos;
		$div->att('data-autopause',$this->autopause);
		$div->att('data-thumb',$this->thumb);
		$div->att('data-mode',$this->mode);
		$div->att('data-shadow',$this->shadow);

		//creo la estructura

		$imagenes=$this->images;
		$thumbs=$this->thumbs;
		$nimagenes=count($imagenes);
		for($i=0;$i<$nimagenes;++$i){
			$imgCnt=new div();
			$imgCnt->att('id','imgCnt_'.$i);
			$imgCnt->att('data-delay',$this->delay);
			$img=new img();
			$img->att('id','img_'.$i);
			$img->att('data-src',$imagenes[$i]);
			$img->att('data-thumb',$thumbs[$i]);
			$imgCnt->addControl($img);
			$div->addControl($imgCnt);
		}


		return $this->libraries().$div . $this->kenBurns_script();

	}
	
	private function libraries(){
		ob_start();
		?>
		
		<link rel="stylesheet" href="<?php echo base_url('js/vendor/cssSlider/960.css'); ?>">
		<!-- link rel="stylesheet" href="<?php //echo base_url('js/vendor/cssSlider/preview.css'); ?>"-->
		<!--  link rel="stylesheet" href="<?php //echo base_url('js/vendor/cssSlider/reset.css'); ?>"-->
		<link rel="stylesheet" href="<?php echo base_url('js/vendor/cssSlider/skin.min.css'); ?>">
		<!-- link rel="stylesheet" href="<?php// echo base_url('js/vendor/cssSlider/text.css'); ?>"-->

		
		<!-- requiere de jquery 1.8.3 maximo, la 1.9 no funciona --> 
		<script src="<?php echo base_url('js/vendor/jquery.pixelentity.kenburnsSlider.min.js'); ?>"></script>
		
		<?php
		return ob_get_clean();
	}

	private function kenBurns_script(){

		ob_start();
		?>
		
		<script>
			$(document).ready(function (){
				
				$(".<?php echo $this->att('class')?>").peKenburnsSlider({externalFont:true});
				var height=$('#<?php echo $this->att('id') ?>').css('height');
				$('#<?php echo $this->att('id') ?>').css('height',(parseInt(height)-50)+'px');
			})
			// for google fonts, handle captions sizing only after fonts are loaded
			$(window).load(function() {
				$(".<?php echo $this->att('class')?>").each(function() {
					$(this).data("peKenburnsSlider").fontsLoaded();
				});
			});
			
		</script>
​
		<?php
			
		return ob_get_clean();
			
	}
}